/**
 * 组织结构员工列表控制器
 */
import $_fn from '~plugins'
import './index.less'
export default ['$scope','$rootScope','$location','$ui','http','$state',function($scope,$rootScope,$location,$ui,http,$state) {
    $scope.$_fn = $_fn
    //初始化对象
    $scope.params={
        pageNum:1,
        positionId:-1,
        departmentId:-1,
        locked:-1
    }
    $rootScope.genXin1="1";
    $scope.$watch('genXin1',function(newValue,oldValue){//更新数据
    	console.log("-----数据监听")
    	if(newValue!=oldValue){
    		console.log('数据要更新了')
    		$rootScope.genXin1="1";
    		$scope.getDada(1,$scope.params)
    	}
    })
	//四级按钮
	$scope.tabMenu = $_fn.getCurrMenu($location.path())
    console.log($scope.tabMenu)
    $scope.subMenu = $scope.tabMenu.children[0].children
    console.log($scope.subMenu)
	$scope.params = $location.search()
	//四级按钮页面跳转方法
	$scope.operation = function (path,item) {
		console.log('111')
        var _path = path.split('@')
        let params = JSON.stringify(item)
        if(_path[0] == 'link'){
            console.log(path)
            $state.go(_path[1], item)
        }
        if(_path[0] == 'alert'){
            $ui.modal({content:"<"+_path[1]+" params="+params+"></"+_path[1]+">"})
        }
   }
	
	$scope.param1={}
	//获取数据的函数
    $scope.getDada = function(page,params){
        params.pageNum = page
        http.post('userListInit.do',params,function (data) {
            if(data.errcode > 0){
                //列表无数据
                if(data.data.userPage.list.length === 0){
                    $scope.isData = true
                    $scope.$apply()
                }
                $scope.$apply(function () {
                    $scope.param1.userPage = data.data.userPage;//分页
                    $scope.param1.list = data.data.userPage.list;
                    $scope.param1.positionList = data.data.positionList;//职位下拉框
                    $scope.param1.deptList = data.data.deptList;//部门下拉框
                    $scope.param1.roles = data.data.roles;//角色下拉框
                })
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
        },function(){
            //报错时
            $scope.isData = true
            $scope.$apply()
        })
    }
	$scope.getDada(1,$scope.params)
    $scope.searchHandle = function () {
      if($scope.params.keyword && $scope.params.type==-1){
        $scope.err.type = true
        $scope.errorToast('左侧字段没有选择')
        return
      }
      $location.search($scope.params)
      $scope.getDada(1,$scope.params)
    }
    $scope.select = [{name:'以租代购',value:1},{name:'信贷方式',value:2}]
    $scope.popup = {
        opened: true
    }

}]
